package spring.framework.study.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import spring.framework.study.mapper.PurchasePlanMapper;
import spring.framework.study.model.purchase.PurchasePlan;

@RestController
@RequestMapping("purchase")
public class TestController {
	
	@Autowired
	private PurchasePlanMapper purchasePlanMapper;
	
	@GetMapping("getPurchasePlan")
	public PurchasePlan getPurchasePlan() {
		return purchasePlanMapper.selectByPrimaryKey(8502L);
	}
	
	@GetMapping("getPurchasePlanPageList")
	public Page<PurchasePlan> getPageList() {
		Page<PurchasePlan> page = new Page<PurchasePlan>(1, 10);
		
		Page<PurchasePlan>  pageData = purchasePlanMapper.selectPage(page, null);
		
		//返回对象得到分页所有数据
	    long pages = pageData.getPages(); //总页数
	    long current = pageData.getCurrent(); //当前页
	    List<PurchasePlan> records = pageData.getRecords(); //查询数据集合
	    long total = pageData.getTotal(); //总记录数
	    boolean hasPrevious = pageData.hasPrevious(); //上一页
	    boolean hasNext = pageData.hasNext();  //下一页

	    System.out.println("page => " + pages);
	    System.out.println("current => " + current);
	    System.out.println("records => " + records);
	    System.out.println("total => " + total);
	    System.out.println("hasPrevious => " + hasPrevious);
	    System.out.println("hasNext =>" + hasNext);
	    return pageData;
	}
}
